package com.backend.service.serviceImpl;

import com.backend.entity.User;
import com.backend.mapper.UserMapper;
import com.backend.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    //登录
    @Override
    public User findByUsername(String username) {
        User user = userMapper.findByUsername(username);
        return user;
    }

    //注册
    @Override
    public void register(String username, String password) {
        userMapper.add(username,password);
    }

    //根据id查找用户
    @Override
    public User findById(Integer userId) {
        User user = userMapper.findById(userId);
        return user;
    }

    //根据用户名修改用户信息
    @Override
    public void updateByUsername(String usernameBefore, String usernameAfter) {
        userMapper.updateByUsername(usernameBefore,usernameAfter);
    }

    //查询用户名是否存在
    @Override
    public int usernameExist(String username) {
        return userMapper.usernameExist(username);
    }

    //修改用户密码
    @Override
    public void updatePwd(Integer id, String newPassword) {
        userMapper.updatePwd(id,newPassword);
    }

    @Override
    public List<User> listAll(Integer pageNumber, Integer pageSize) {
        pageNumber = (pageNumber - 1)* pageSize;
        return userMapper.listAll(pageNumber,pageSize);
    }

    @Override
    public long listAllNum() {
        return userMapper.listAllNum();
    }

    @Override
    public void deleteUser(Integer deleteId) {
        userMapper.deleteUser(deleteId);
    }


}
